﻿using NUnit.Framework;
using TeamsPortal.DataAccess;

namespace TeamsPortal.Tests.DataAccess
{
    [TestFixture]
    public class ImageDataAccessTests : BaseRollbackTest
    {
        [Test]
        public void AddTest()
        {
            const string path = "path";
            User user = DATestsHelper.CreateUser("username", UserRole.Member);
            
            var da = new ImageInfoDataAccess();
            ImageInfo saved = da.Add(path, user.Id);

            Assert.IsNotNull(saved);
            Assert.AreEqual(path, saved.Path);
            Assert.AreNotEqual(0, saved.Id);
        }

        [Test]
        public void GetById()
        {
            const string path = "path";
            User user = DATestsHelper.CreateUser("username", UserRole.Member);

            var da = new ImageInfoDataAccess();
            ImageInfo saved = da.Add(path, user.Id);

            ImageInfo loaded = da.Get(saved.Id);

            Assert.IsNotNull(loaded);
            Assert.AreEqual(saved.Id, loaded.Id);
            Assert.AreEqual(path, loaded.Path);
        }

        [Test]
        public void RemoveById()
        {
            const string path = "path";
            User user = DATestsHelper.CreateUser("username", UserRole.Member);

            var da = new ImageInfoDataAccess();
            ImageInfo saved = da.Add(path, user.Id);
            
            //Act
            da.Remove(saved.Id);

            ImageInfo loaded = da.Get(saved.Id);
            Assert.IsNull(loaded);
        }
    }
}
